package com.liuc.practice.server.servlet;

import com.liuc.practice.server.pojo.Request;
import com.liuc.practice.server.pojo.Response;

import java.io.IOException;

/**
 * @Author Liu Chang
 * @Date 2021/7/22 11:02 下午
 *
 * 模版方法类
 */
public abstract class HttpServlet implements Servlet{

    /**
     * 模版方法
     * @param request
     * @param response
     * @throws IOException
     * @throws InterruptedException
     */
    public abstract void doGet(Request request, Response response) throws IOException, InterruptedException;
    public abstract void doPost(Request request, Response response) throws IOException;

    @Override
    public void service(Request request, Response response) throws Exception {
        if ("Get".equalsIgnoreCase(request.getMethod())) {
            doGet(request, response);
        } else {
            doPost(request, response);
        }
    }
}
